﻿using MediatR;
using W.Purchase.API.Application.Command;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler
{
    public class VendorUpdateCommandHandler : IRequestHandler<VendorUpdateCommand, int>
    {
        private readonly IVendorRepository vendorRepository;

        public VendorUpdateCommandHandler(IVendorRepository vendorRepository)
        {
            this.vendorRepository = vendorRepository;
        }

        public async Task<int> Handle(VendorUpdateCommand request, CancellationToken cancellationToken)
        {
            request.IsDelete = false;
            return await vendorRepository.Update(new Domain.Vendor() { VendorId = request.VendorId, VendorNo = request.VendorNo, VendorName = request.VendorName, VendorState = request.VendorState, VendorTypeId = request.VendorTypeId, VendorPhone = request.VendorPhone, VendorFax = request.VendorFax, VendorEmail = request.VendorEmail, VendorContact = request.VendorContact, VendorAddress = request.VendorAddress, VendorDesc = request.VendorDesc, VendorRemarks = request.VendorRemarks, office_id = request.office_id, user_id = request.user_id, CreateName = request.CreateName, CreateTime = request.CreateTime, UpdateName = request.UpdateName, UpdateTime = request.UpdateTime, DeleteName = request.DeleteName, DeleteTime = request.DeleteTime, IsDelete = request.IsDelete });
        }
    }
}
